#include "cutDialog.h"

cutDialog::cutDialog(QWidget *parent, Qt::WFlags flags )
	: QDialog(parent, flags)
{
	ui.setupUi(this);

	//Connects
	connect(this, SIGNAL(accepted()), this, SLOT(select()));
	connect(this->ui.partsButton, SIGNAL(clicked()), this, SLOT(setPartsEnabled()));
	connect(this->ui.timeButton, SIGNAL(clicked()), this, SLOT(setTimeEnabled()));

	//Inicializacion
	this->ui.timeLine->setInputMask("99:99");
	this->ui.timeLine->setText("00:00");
	this->ui.partsLine->setInputMask("99");
	this->ui.partsLine->setText("0");
	this->ui.timeLine->setEnabled(false);
	this->ui.partsLine->setEnabled(false);
	this->setWindowTitle("Select split");
}
cutDialog::~cutDialog()
{}

void cutDialog::select()
{
	int selection;
	QString selection_2;

	if (this->ui.partsButton->isChecked() == true)
	{
		selection = 0;
		selection_2 = this->ui.partsLine->text();
		int n = selection_2.toInt();//Sacamos en cuantas partas se eligio
		if(n > 100 || n < 1)
		{
			QMessageBox msg;
			msg.setText("Invalid number of parts. Please introduce a number between 1 and 100");
			msg.setWindowTitle("Incorrect number of parts");
			msg.exec();
		}
	}
	else
	{
		if(this->ui.timeButton->isChecked() == true)
		{
			selection = 1;
			selection_2 = this->ui.timeLine->text();
		}
		else
			selection = -1;
	}
	

	emit seleccion(selection, selection_2);
}

void cutDialog::setPartsEnabled()
{
	if (this->ui.partsButton->isChecked())
	{
		this->ui.partsLine->setCursorPosition(1);
		this->ui.partsLine->setEnabled(true);
		this->ui.timeLine->setEnabled(false);
	}
}

void cutDialog::setTimeEnabled()
{
	if (this->ui.timeButton->isChecked())
	{
		this->ui.timeLine->setEnabled(true);
		this->ui.partsLine->setEnabled(false);
	}
}